#include "Config.h"

#include <windows.h>

#define INI_FILE "Log cleaner.ini"

Config::Config() {
    deleteTime = false;
    flag = DEFAULT_FLAG;
    pluginName = "";
    loadFromFile();
}

void Config::loadFromFile() {
    flag = GetPrivateProfileInt("clean", "flag", DEFAULT_FLAG, INI_FILE);
    deleteTime = GetPrivateProfileInt("clean", "deletetime", false, INI_FILE);
    char plugin[1024] = {0};
    GetPrivateProfileString("plugin", "name", "", plugin, 255, INI_FILE); 
    pluginName = plugin;
}

void Config::saveToFile() {
    char buf[32] = {0};
    itoa(flag, buf, 10);
    WritePrivateProfileString("clean", "flag", buf, INI_FILE);
    WritePrivateProfileString("clean", "deletetime", deleteTime ? "1" : "0", INI_FILE);
    WritePrivateProfileString("plugin", "name", pluginName.c_str(), INI_FILE);        
}

void Config::setFlag(unsigned int flag) {
    this->flag = flag;
}

void Config::setDeleteTime(bool deleteTime) {
    this->deleteTime = deleteTime;
}

void Config::setPluginName(string name) {
    this->pluginName = name;
}
